/*
 * @功能描述: 
 * @版本: v1.0.0
 * @作者: LuAn
 * @Date: 2021-08-30 20:30:43
 * @LastEditTime: 2021-08-31 19:07:03
 */
#include "test.h"
#include "bsp_delay.h"
#include "bsp_beep.h"
#include "bsp_key.h"
#include "bsp_led.h"
#define KEY_PRESS 0
#define KEY_RELEASE 1

void test_main_key()
{

  beep_init();
  key_init();
  led_init();
  int keyvalue = 0;
  int nrelease = 0;
  int state = KEY_RELEASE;
  int i = 0;
  while (1)
  {
    i++;
    keyvalue = key_getvalue();
    if (keyvalue == 0 && state == KEY_PRESS)
    {
      nrelease++;
      if (nrelease > 5)
      {
        state = KEY_RELEASE;
        beep_switch(OFF);
        led_switch(0, OFF);
      }
    }
    else if (state == KEY_RELEASE && keyvalue != 0)
    {
      nrelease = 0;
      state = KEY_PRESS;
      beep_switch(ON);
      led_switch(0, ON);
    }
    delay(10);
  }
}
